import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.io.IOException;

import javax.swing.JFrame;


public class editor extends JFrame implements MouseListener,MouseMotionListener,KeyListener,Runnable {

	editor(){
		addKeyListener((KeyListener)this);
		addMouseMotionListener((MouseMotionListener) this);
		addMouseListener((MouseListener) this);
		setSize(VarHolder.ScreenWidth,VarHolder.ScreenHeight);
		setVisible(true);
		setResizable(false);
		


		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Array.MakeArray();		
	}
	

	public void paint(Graphics g){
		VarHolder.dbImage = createImage(getWidth(), getHeight());
		VarHolder.dbg = VarHolder.dbImage.getGraphics();
		paintComponent(VarHolder.dbg);
		g.drawImage(VarHolder.dbImage, 0,0, this);	
		
		
	}
	public void paintComponent(Graphics g){
		if(VarHolder.Paused == false){
			ScreenGraphics.paintTiles(g);
		}
		repaint();
		
	}
	
	public static void main(String[] args) throws IOException {
		editor a1 = new editor();
		
		SetSubImages a2 = new SetSubImages();
		
		Thread t1 = new Thread(a1);
		t1.start();	
		
	}


	@Override
	public void mouseClicked(MouseEvent e) {
		/*
		ChangeTile.PlaceBlock();
		
		*/
	}


	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void mousePressed(MouseEvent e) {

	}


	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void mouseDragged(MouseEvent e) {
		
		/*
		ChangeTile.PlaceBlock();
		VarHolder.MouseX = (int)(e.getX()/VarHolder.TileWidth);
		VarHolder.MouseY =  (int)(e.getY()/VarHolder.TileHeight);
		*/
		
	}


	@Override
	public void mouseMoved(MouseEvent e) {
		VarHolder.MouseX = (int)(e.getX()/VarHolder.TileWidth);
		VarHolder.MouseY =  (int)(e.getY()/VarHolder.TileHeight);
		
	}


	@Override
	public void keyPressed(KeyEvent e) {
		
		/*
		
		if(e.getKeyCode() == KeyEvent.VK_D){
			VarHolder.CameraX = -10;
		}
		if(e.getKeyCode() == KeyEvent.VK_A){
			VarHolder.CameraX = 10;
		}
		if(e.getKeyCode() == KeyEvent.VK_W){
			VarHolder.CameraY = 10;
		}
		if(e.getKeyCode() == KeyEvent.VK_S){
			VarHolder.CameraY = -10;
		}
		
		*/

	}


	@Override
	public void keyReleased(KeyEvent e) {
		/*
		
		if(e.getKeyCode() == KeyEvent.VK_E){
			ChangeTile.ChangePreviewTile(1);
		}
		if(e.getKeyCode() == KeyEvent.VK_Q){
			ChangeTile.ChangePreviewTile(-1);
		}
		
		if(e.getKeyCode() == KeyEvent.VK_P){
			try {
				SaveLevel.Save();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		}
		if(e.getKeyCode() == KeyEvent.VK_L){
			//LoadLevel.Load();
		}
		
		
		if(e.getKeyCode() == KeyEvent.VK_D){
			VarHolder.CameraX = 0;
		}
		if(e.getKeyCode() == KeyEvent.VK_A){
			VarHolder.CameraX = 0;
		}
		if(e.getKeyCode() == KeyEvent.VK_W){
			VarHolder.CameraY = 0;
		}
		if(e.getKeyCode() == KeyEvent.VK_S){
			VarHolder.CameraY = 0;
		}
		
		*/

		
		
	}


	@Override
	public void keyTyped(KeyEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void run() {
		while(true){
			try {
				Thread.sleep(500);
				
				Ball.ball();
				Paddle.paintPaddle();
				
				
				//CameraMotions.CameraMove();
			} catch (InterruptedException e) {
				System.out.println("Thread Gone Ploppers");
			}
		}
		
	}
}
